package com.mfnote.adapter;

import java.util.ArrayList;
import java.util.HashMap;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewGroup.LayoutParams;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.mfnote.db.dao.RecordDao;
import com.mfnote.view.R;

public class RecordAdapter extends BaseAdapter {
	private LayoutInflater inflater = null;
	private ArrayList<HashMap<String, Object>> list = null;
	private View view = null;
	private HashMap<String, Object> map = null;
	private TextView list_item_file_name_tv = null;
	private TextView list_item_file_time_tv = null;
	private TextView list_item_file_size_tv = null;

	public RecordAdapter(Context context) {
		
		inflater = LayoutInflater.from(context);
		list = new RecordDao(context).getRecordAllCount();
	}

	@Override
	public int getCount() {
		return list.size();
	}

	@Override
	public Object getItem(int position) {
		return list.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		if (convertView != null) {
			view = convertView;
		} else {
			view = inflater.inflate(R.layout.record_list_item, null);
		}
		//LayoutParams params=new LayoutParams()
		map = list.get(position);
		list_item_file_name_tv = (TextView) view.findViewById(R.id.list_item_file_name_tv);
		list_item_file_time_tv = (TextView) view.findViewById(R.id.list_item_file_time_tv);
		list_item_file_size_tv = (TextView) view.findViewById(R.id.list_item_file_size_tv);

		list_item_file_name_tv.setText(map.get("title").toString());
		list_item_file_time_tv.setText(map.get("time").toString());
				
		list_item_file_size_tv.setText(map.get("recordLength").toString()+"K");
		
		return view;
	}

}
